<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

/**
 * Facilitate the collection of a date with dropmenus
 * @author Anthony Gallon
 * @package Antz
 */

/**
 * Facilitate the collection of a date with dropmenus
 * @author Anthony Gallon
 * @package Antz
 */
class JFX_Form_Components_TimeSelect extends JFX_Form_Component
{
    /**
     * Contains the options
     * @var array $options
     */
    protected $options = array();

    /**
     * Set our initia values
     * @param string $name
     * @param string $label
     * @param mixed $value
     */
    public function __construct($name, $label, $value=''){
        $this->id = 'sel'.rand();
        $this->name = $name;
        $this->label = $label;
        if($value=='') $value = array('hour'=>date('H'), 'minute'=>date('i'));
        $this->value = $value;
        $this->setLang('en');
    }

    /**
     * Set our language
     * @param string $lang
     */
    public function setLang($lang='en'){
        $lang = 'en';
        switch($lang){
            case 'en':

            break;
        }
    }

    /**
     * Get our element as an HTML string
     * @global object $gCms
     * @return string $html
     */
    public function render(){
        $CONFIG = JFX::registry('config');
     	if($this->required) $this->aftertext = '<span class="required"><img src="'.$CONFIG->baseUrl.'/jfx/images/required.gif" alt="Required" /></span>'.$this->aftertext;

        // generate the hour options
        $this->hourSel = new JFX_Form_Components_DateSelect_Select($this->name.'Hour', $this->value['hour']);
        for($i=0; $i<=23; $i++){
            $this->hourSel->add($i);
        };
        // generate the minute options
        $this->minSel = new JFX_Form_Components_DateSelect_Select($this->name.'Minute', $this->value['minute']);
        for($i=0; $i<60; $i++){
            $this->minSel->add($i);
        };

        $returnString = $this->hourSel->render().$this->minSel->render();
        if($this->showLabel) $returnString = '<label>'.$this->label.'</label>'.$returnString.'<div class="aftertext">'.$this->aftertext.'</div>';
        if($this->wrap) return $this->wrap($returnString);
        else return $returnString;
    }
}
